<template>
  <div>
    <van-nav-bar
      :title="
        comment.reply_count > 0 ? `${comment.reply_count}条记录` : '暂无记录'
      "
    >
      <van-icon name="cross" slot="left" @click="$emit('close')" />
    </van-nav-bar>
    <div class="post-scroll">
      <comment-item :comment="comment"></comment-item>
      <comment-list
        :source="comment.com_id"
        type="c"
        :list="commentList"
      ></comment-list>
    </div>
    <div class="post-wrap">
      <van-button class="post-btn" size="small" round @click="isPostShow = true"
        >写评论</van-button
      >
    </div>
    <van-popup v-model="isPostShow" position="bottom">
      <comment-post
        :target="comment.com_id"
        @post-success="onPostSuccess"
      ></comment-post>
    </van-popup>
  </div>
</template>

<script>
import commentItem from './comment-item.vue'
import commentList from './comment-list.vue'
import commentPost from './comment-post.vue'

export default {
  name: 'commentReply',
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  components: {
    commentItem,
    commentList,
    commentPost
  },
  data () {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  created () {

  },
  methods: {
    onPostSuccess (data) {
      this.isPostShow = false
      this.commentList.unshift(data.new_obj)
      this.comment.reply_count++
    }
  }
}
</script>

<style lang="less" scoped>
.post-scroll {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
